home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / g++ / ACG.h < prev    next >
C/C++ Source or Header  |  1995-02-06  |  2KB  |  70 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  5.  
  6. This file is part of the GNU C++ Library.  This library is free
  7. software; you can redistribute it and/or modify it under the terms of
  8. the GNU Library General Public License as published by the Free
  9. Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.  This library is distributed in the hope
  11. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  12. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. PURPOSE.  See the GNU Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #ifndef _ACG_h
  19. #define _ACG_h 1 
  20.  
  21. #include <RNG.h>
  22. #include <math.h>
  23. #ifdef __GNUG__
  24. #pragma interface
  25. #pragma cplusplus
  26. #endif
  27.  
  28. //
  29. //    Additive number generator. This method is presented in Volume II
  30. //    of The Art of Computer Programming by Knuth. I've coded the algorithm
  31. //    and have added the extensions by Andres Nowatzyk of CMU to randomize
  32. //    the result of algorithm M a bit    by using an LCG & a spatial
  33. //    permutation table.
  34. //
  35. //    The version presented uses the same constants for the LCG that Andres
  36. //    uses (chosen by trial & error). The spatial permutation table is
  37. //    the same size (it's based on word size). This is for 32-bit words.
  38. //
  39. //    The ``auxillary table'' used by the LCG table varies in size, and
  40. //    is chosen to be the the smallest power of two which is larger than
  41. //    twice the size of the state table.
  42. //
  43.  
  44. class ACG : public RNG {
  45.  
  46.     unsigned long initialSeed;    // used to reset generator
  47.     int initialTableEntry;
  48.  
  49.     unsigned long *state;
  50.     unsigned long *auxState;
  51.     short stateSize;
  52.     short auxSize;
  53.     unsigned long lcgRecurr;
  54.     short j;
  55.     short k;
  56.  
  57. protected:
  58.  
  59. public:
  60.     ACG(unsigned long seed = 0, int size = 55);
  61.     virtual ~ACG();
  62.     //
  63.     // Return a long-words word of random bits
  64.     //
  65.     virtual unsigned long asLong();
  66.     virtual void reset();
  67. };
  68.  
  69. #endif
  70.